'use strict';

/**
 * @description 帖子表模型
 * */
module.exports = app => {
  const { STRING, INTEGER, TEXT } = app.Sequelize;

  const Comment = app.model.define('comment', {
    title: {
      type: STRING(50),
      allowNull: false,
      comment: '标题',
    },
    content: {
      type: TEXT,
      allowNull: false,
      comment: '相关内容',
    },
    pictures: {
      type: TEXT,
      allowNull: true,
      comment: '相关图片',
    },
    uid: {
      type: INTEGER,
      allowNull: false,
      comment: '发帖人id',
    },
    houseId: {
      type: INTEGER,
      allowNull: true,
      comment: '房子id',
    },
    status: {
      type: INTEGER,
      allowNull: true,
      defaultValue: 1,
      comment: '审核状态 1-待审核 2-同意 3-拒绝',
    },
  });

  Comment.associate = () => {
    app.model.Comment.belongsTo(app.model.User, {
      foreignKey: 'uid',
    });
    app.model.Comment.belongsTo(app.model.House, {
      foreignKey: 'houseId',
    });
    app.model.Comment.hasMany(app.model.Reply, {
      foreignKey: 'cid',
    });
  };

  return Comment;
};
